<template>
  <div>
   <el-breadcrumb separator="/">
        <el-breadcrumb-item v-for="(v,i) in this.$route.meta.arr" :key="i">{{v}}</el-breadcrumb-item>
      </el-breadcrumb>
      
    <el-table v-if="arr" :data="arr" style="width: 100%">
      <el-table-column prop="uname" label="用户名" width="180">
      </el-table-column>
      <el-table-column prop="upwd" label="密码" width="180"> </el-table-column>
      <el-table-column prop="address" label="操作">
        <template slot-scope="scope">
          <el-button size="mini" @click="handleEdit(scope.$index, scope.row)"
            >编辑</el-button
          >
          <el-button
            size="mini"
            type="danger"
            @click="handleDelete(scope.$index, scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 修改 -->
    <el-dialog title="收货地址" :visible.sync="dialogFormVisible">
      <el-form :model="form">
        <el-form-item label="修改用户名" :label-width="formLabelWidth">
          <el-input v-model="form.name" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="修改密码" :label-width="formLabelWidth">
          <el-input v-model="form.pwd" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogFormVisible = false">取消</el-button>
        <el-button type="primary" @click="dataupdate()">确 定</el-button>
      </div>
    </el-dialog>
    <!-- 删除弹框 -->
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <span>这是一段信息</span>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { homelink } from "@/api/homeapi.js";
import { loginlink } from "@/api/loginapi";
export default {
  name: "HtDemoa",
  data() {
    return {
      arr: [],
      dialogFormVisible: false,
      dialogVisible: false,
      form: {
        name: "",
        pwd: "",
      },
      oldname: "",
      formLabelWidth: "120px",
    };
  },
  mounted() {
    homelink("/api/a").then((ok) => {
      // console.log(ok.data);
      this.arr = ok.data;
    });
  },
  methods: {
    dataupdate() {
      this.dialogFormVisible = false;
      let usp = new URLSearchParams();
      usp.append("oldname", this.oldname);
      usp.append("uname", this.form.name);
      usp.append("upwd", this.form.pwd);
      loginlink("/api/update", usp).then((ok) => {
        console.log(ok);
      });
       homelink("/api/a").then((ok) => {
      console.log(ok.data);
      this.arr = ok.data;
    });
      this.form.name = "";
      this.form.pwd = "";
    },
    handleEdit(index, row) {
      this.dialogFormVisible = true;
      console.log(index, row);
      this.oldname = row.uname;
    },
    handleDelete(index, row) {
      this.dialogVisible = true;
      console.log(index, row);
    },
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },
  },
};
</script>

<style lang="scss" scoped>
</style>